
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>

 #include "project.h"
 #include "fileControl.h"
 #include "indivResultsSelect.h"
 #include "indivResultsData.h"


int showResultsSelectStudent(void)
{
    int frame,button1,button2,label,choice,obj;
    student_t student;
    char displayString[34];

    int studentIndex = 0;
    student_t selectedStudent;

    frame = j_frame("Indivdual Results");
    j_show(frame);

    j_setsize(frame,600,600);

    button1= j_button(frame,"Ok");
    button2= j_button(frame,"Cancel");

    j_setsize(button1,80,20);
    j_setsize(button2,80,20);

    j_setpos(button1,200,500);
    j_setpos(button2,400,500);

    label=j_label(frame,"Select Student :");
    j_setpos(label,100,200);

    choice =j_choice(frame);
    j_setpos(choice,200,200);
    j_setsize(choice,300,20);


    while(nextStudentExists())
    {
        student = getNextStudent();

        strcpy(displayString, student.id);
        strcat(displayString, " - ");
        strcat(displayString, student.firstName);
        strcat(displayString, " ");
        strcat(displayString, student.surName);

        j_additem(choice, displayString);
    }

    while(1)
    {
        obj=j_nextaction();

        if(obj==choice)
        {
           studentIndex = j_getselect(choice);
        }
        else if(obj == button1)
        {
            j_hide(frame);
            getNthStudent(studentIndex, &selectedStudent);
            openIndividualResultScreen(selectedStudent);
        }
        else if(obj == button2)
        {
            j_hide(frame);
           // mainscreen()
        }
        else if(obj == frame)
        {
            j_quit();
        //closes the program totally
        }
    }

}
